﻿@using OSBIDE.Library.Models
@using OSBIDE.Web.Models.ViewModels
@using OSBIDE.Web.Models
@using OSBIDE.Library
@model OSBIDE.Web.Models.ViewModels.ProfileViewModel
@{
    ViewBag.Title = Model.User.FullName;
    OsbideUser currentUser = ViewBag.CurrentUser;
}

<section>
    <div class="feed-item-single-left">
        <img src="@Url.Action("Picture", "Profile", new { id = Model.User.Id })" title="profile image" alt="profile image" />
    </div>
    <div class="feed-item-single-right">
        <h1 style="display: inline;">@Model.User.FirstAndLastName</h1>
        @if (ViewBag.CurrentUser.Id == Model.User.Id)
        {
            <span>@Html.ActionLink("(Edit your profile)", "Edit")</span>
        }
        <table>
            <tr>
                <td><strong>@Model.Score.Score</strong> points</td>
            </tr>
            <tr>
                <td><strong>@Model.NumberOfPosts</strong> post(s)</td>
            </tr>
            <tr>
                <td><strong>@Model.NumberOfComments</strong> comment(s)</td>
            </tr>
        </table>
    </div>
</section>
@if (Model.User.Id == currentUser.Id)
{
    int rowCounter = 0;
    <section id="subscriptions">
        <h1>My Subscriptions</h1>
        @if (Model.EventLogSubscriptions.Count() == 0)
        {
            @:You don't have any subscriptions.
        }
        else
        {
            <table id="subscriptions-table">
                <thead>
                    <tr>
                        <th>&nbsp;</th>
                        <th>Author</th>
                        <th>Event Type</th>
                        <th>Last Activity Date</th>
                        <th># Comments</th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (AggregateFeedItem item in Model.EventLogSubscriptions)
                    {
                        rowCounter++;
                        string rowClass = "normal-row";
                        if (rowCounter % 2 == 0)
                        {
                            rowClass = "alt-row";
                        }
                        var lastComment = (from comment in item.Comments
                                           orderby comment.DatePosted descending
                                           select comment).FirstOrDefault();
                        string lastCommentText = "not available";
                        if (lastComment != null)
                        {
                            lastCommentText = lastComment.DatePosted.ToString("MM/dd @ hh:mmtt");
                        }
                    
                        <tr class="@rowClass">
                            <td>
                                <img src="@Url.Action("Picture", "Profile", new { id = item.Creator.Id, size = 24 })" height="24" width="24" title="profile image" alt="profile image" /></td>
                            <td>
                                @Html.ActionLink(item.Creator.FirstAndLastName, "Index", "Profile", new { id = item.Creator.Id, component = OsbideVsComponent.UserProfile }, new { })
                            </td>
                            <td>@item.PrettyName</td>
                            <td>@lastCommentText</td>
                            <td>@item.Comments.Count</td>
                            <td>
                                @Html.ActionLink("View", "Details", "Feed", new { id = item.Items.FirstOrDefault().LogId, component = OsbideVsComponent.FeedDetails }, new { })
                                <a style="padding-left:10px;" href="@Url.Action("UnfollowPost", "Feed", new { id = item.Items.FirstOrDefault().LogId, returnUrl = Request.Url.AbsoluteUri })">
                                    <img src="~/Content/icons/unfollow.png" title="unfollow" alt="unfollow" />
                                </a>

                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        }
    </section>
}
<section id="recent-comments">
    <h1>Recent Comments by @Model.User.FirstName</h1>
    @if (Model.RecentComments.Count() == 0)
    {
        @:No recent comments.
    }
    else
    {
        <table class="comments-table">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Event Author</th>
                    <th>Message</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (LogComment comment in Model.RecentComments)
                {
                    <tr>
                        <td class="comments-table-date"><time 
                class="utc-time"
                datetime="@Helpers.DateAsUnixTime(comment.DatePosted)" 
                data-original-date="@Helpers.RawDate(comment.DatePosted)" 
                data-date-format="MM/DD/YYYY hh:mm A">
                            @comment.DatePosted.ToString("MM/dd @ hh:mmtt") (UTC)
                        </time></td>
                        <td class="comments-table-message-author">@Html.ActionLink(comment.Log.Sender.FirstAndLastName, "Index", "Profile", new { id = comment.AuthorId, component = OsbideVsComponent.UserProfile }, new { })</td>
                        <td class="comments-table-content">@comment.Content</td>
                        <td>@Html.ActionLink("View Discussion", "Details", "Feed", new { id = comment.Log.Id, component = OsbideVsComponent.FeedDetails }, new { })</td>
                    </tr>
                }
            </tbody>
        </table>
    }
</section>
<section id="recent-comments-by-others">
    <h1>Recent Comments Made on @Model.User.FirstName's Events</h1>
    @if (Model.RecentComments.Count() == 0)
    {
        @:No recent comments.
    }
    else
    {
        <table class="comments-table">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Message Author</th>
                    <th>Message</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (LogComment comment in Model.CommentsMadeByOthers)
                {
                    <tr>
                        <td class="comments-table-date"><time 
                class="utc-time"
                datetime="@Helpers.DateAsUnixTime(comment.DatePosted)" 
                data-original-date="@Helpers.RawDate(comment.DatePosted)" 
                data-date-format="MM/DD/YYYY hh:mm A">
                            @comment.DatePosted.ToString("MM/dd @ hh:mmtt") (UTC)
                        </time></td>
                        <td class="comments-table-message-author">@Html.ActionLink(comment.Author.FirstAndLastName, "Index", "Profile", new { id = comment.AuthorId, component = OsbideVsComponent.UserProfile }, new { })</td>
                        <td class="comments-table-content">@comment.Content</td>
                        <td>@Html.ActionLink("View Discussion", "Details", "Feed", new { id = comment.Log.Id, component = OsbideVsComponent.FeedDetails }, new { })</td>
                    </tr>
                }
            </tbody>
        </table>
    }
</section>
<section>
    <h1>Recent Activity</h1>
    @Html.Partial("Feed/_Feed", Model.Feed)
</section>
